<template>
    <n-divider title-placement="left">采用的算法:</n-divider>
    <n-radio-group v-model:value="value" name="radiogroup" @change="changeValue">
        <div v-if="algorithmsGM.length !== 0">
            国密算法：
            <n-radio v-for="algorithm in algorithmsGM" :key="algorithm.label" :value="algorithm.value">
                {{ algorithm.label }}
            </n-radio>
            <n-divider dashed />
        </div>
        <div v-if="algorithmsGJ.length !== 0">
            非国密算法：
            <n-radio v-for="algorithm in algorithmsGJ" :key="algorithm.label" :value="algorithm.value">
                {{ algorithm.label }}
            </n-radio>
            <n-divider dashed />
        </div>
        <div v-if="algorithmsHJ.length !== 0">
            缓解措施：
            <n-radio v-for="algorithm in algorithmsHJ" :key="algorithm.label" :value="algorithm.value">
                {{ algorithm.label }}
            </n-radio>
            <n-divider dashed />
        </div>
        <div>
            高危风险：
            <n-radio v-for="algorithm in algorithmsGW" :key="algorithm.label" :value="algorithm.value">
                {{ algorithm.label }}
            </n-radio>
            <n-radio value="0">无</n-radio>
        </div>
    </n-radio-group>
</template>

<script lang="ts" setup>
import { ref, onMounted } from 'vue'
import { NRadio, NRadioGroup, NDivider } from 'naive-ui'
import type { RadioProps } from 'naive-ui'
import requset from "@/utils/requset"
import type { response } from "@/utils/requset"
import type { algorithmResopne } from "@/utils/interfaces/respone"

const props = defineProps<{
    pointId: number,
    value: number,
}>()

const emitFn = defineEmits(['changeVaule'])

function changeValue() {
    emitFn('changeVaule', value.value)
}

const value = ref<number>()

const algorithmsGM = ref<RadioProps[]>([])
const algorithmsGJ = ref<RadioProps[]>([])
const algorithmsHJ = ref<RadioProps[]>([])
const algorithmsGW = ref<RadioProps[]>([])

function getData() {
    requset.get('/project/getAlgorithmByPointId', {
        pointId: props.pointId,
    }).then((res: response<algorithmResopne[]>) => {
        if (res.status !== 200) {
            return;
        }
        let data = res.data.data;
        for (let algorithm of data) {
            let algorithmRadio: RadioProps = {
                label: algorithm.name,
                value: algorithm.id
            }
            switch (algorithm.type) {
                case 0:
                    algorithmsGW.value.push(algorithmRadio)
                    break;
                case 1:
                    algorithmsHJ.value.push(algorithmRadio)
                    break;
                case 2:
                    algorithmsGJ.value.push(algorithmRadio)
                    break;
                case 3:
                    algorithmsGM.value.push(algorithmRadio)
                    break;
            }
        }
    })
}


onMounted(() => {
    // console.log(props)
    value.value = props.value
    getData()
})

</script>

<style></style>